package com.demo.model;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.Set;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
//public class SecurityUser extends User implements UserDetails {

public class SecurityUser implements UserDetails {
    private Integer id;
    /**
     * 登录账号
     */
    @TableField(value = "login_act")
    private String loginAct;

    /**
     * 登录密码
     */
    @TableField(value = "login_pwd")
    private String loginPwd;

    /**
     * 用户姓名
     */
    @TableField(value = "`name`")
    private String name;

    /**
     * 用户手机
     */
    @TableField(value = "phone")
    private String phone;

    /**
     * 用户邮箱
     */
    @TableField(value = "email")
    private String email;

    /**
     * 账户是否没有过期，0已过期 1正常
     */
    @TableField(value = "account_no_expired")
    private Integer accountNoExpired;

    /**
     * 密码是否没有过期，0已过期 1正常
     */
    @TableField(value = "credentials_no_expired")
    private Integer credentialsNoExpired;

    /**
     * 账号是否没有锁定，0已锁定 1正常
     */
    @TableField(value = "account_no_locked")
    private Integer accountNoLocked;

    /**
     * 账号是否启用，0禁用 1启用
     */
    @TableField(value = "account_enabled")
    private Integer accountEnabled;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private Date createTime;

    /**
     * 创建人
     */
    @TableField(value = "create_by")
    private Integer createBy;


    /**
     * 最近登录时间
     */
    @TableField(value = "last_login_time")
    private Date lastLoginTime;
    private Set<String> permissionLIst;

    // 添加权限集合字段
    private Collection<? extends GrantedAuthority> authorities;
    private boolean enabled;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.loginPwd;
    }

    @Override
    public String getUsername() {
        return this.loginAct;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
